package Framework;

public class Game
{
	private final int DEFAULT_NUMBER_OF_PLAYERS = 2;
	private final int DEFAULT_NUMBER_OF_TURNS = 20;
	private final int DEFAULT_MAX_NUMBER_OF_PLAYERS = 2;
	private final int DEFAULT_NUMBER_OF_DICES = 2;
	private final int DEFAULT_NUMBER_DICE_FACES = 6;
	
	private int numberOfTurns;
	private int actualTurn = 1;
	
	private GameStrategy strategy;
	
	private int numberOfFacesDice;
	private int numberOfPlayers;
	private int numberMaxOfPlayers;
	private Player actualPlayer;
	private PlayerCollection firstPlayer;
	private PlayerCollection players;
	private DiceCollection dices;
	private Player winner;
	
	public Game()
	{ 
		setPlayers(new PlayerCollection(new Player("test")));
	}
	
	public Game(GameStrategy gs)
	{
		strategy = gs;
		strategy.SetupGame(this);
	}
	
	public int Play()
	{
		return strategy.Play(this);
	}
	
	public void startNewGame()
	{
		strategy.SetupGame(this);
	}
	
	public void AddPlayer(String playerName)
	{
		if (getPlayers() == null)
		{
			setPlayers(new PlayerCollection(new Player(playerName)));
			firstPlayer = getPlayers();
			actualPlayer = getPlayers().getObject();
		}
		else
			getPlayers().add(new PlayerCollection(new Player(playerName)));
	}	

	/******************************************************
	 **************** MUTATEURS/ACCESSEURS ****************
	 ******************************************************/
	/**
	 * @return the numberOfPlayers
	 */
	public int getNumberOfPlayers() 
	{
		return numberOfPlayers;
	}

	/**
	 * @param numberOfPlayers the numberOfPlayers to set
	 */
	public void setNumberOfPlayers(int numberOfPlayers) 
	{
		this.numberOfPlayers = numberOfPlayers;
	}

	/**
	 * @return the winner
	 */
	public Player getWinner() 
	{
		return winner;
	}

	/**
	 * @param winner the winner to set
	 */
	public void setWinner(Player winner) 
	{
		this.winner = winner;
	}

	/**
	 * @return the numberMaxOfPlayers
	 */
	public int getNumberMaxOfPlayers() {
		return numberMaxOfPlayers;
	}

	/**
	 * @param numberMaxOfPlayers the numberMaxOfPlayers to set
	 */
	public void setNumberMaxOfPlayers(int numberMaxOfPlayers) {
		this.numberMaxOfPlayers = numberMaxOfPlayers;
	}
	
	public void setNumberDiceFaces(int n)
	{
		numberOfFacesDice = n;
	}
	
	public void setNumberOfDices(int n)
	{
		if (getDices() == null)
		{
			setDices(new DiceCollection(new Dice(numberOfFacesDice)));
			--n;
		}
		
		for (int i = 0; i < n; ++i)
			getDices().add(new DiceCollection(new Dice(numberOfFacesDice)));
	}

	/**
	 * @return the numberOfTurns
	 */
	public int getNumberOfTurns() {
		return numberOfTurns;
	}

	/**
	 * @param numberOfTurns the numberOfTurns to set
	 */
	public void setNumberOfTurns(int numberOfTurns) {
		this.numberOfTurns = numberOfTurns;
	}

	/**
	 * @return the players
	 */
	public PlayerCollection getPlayers() {
		return players;
	}

	/**
	 * @param players the players to set
	 */
	public void setPlayers(PlayerCollection players) {
		this.players = players;
	}

	/**
	 * @return the actualPlayer
	 */
	public Player getActualPlayer() {
		return actualPlayer;
	}

	/**
	 * @param actualPlayer the actualPlayer to set
	 */
	public void setActualPlayer(Player actualPlayer) {
		this.actualPlayer = actualPlayer;
	}

	/**
	 * @return the dices
	 */
	public DiceCollection getDices() {
		return dices;
	}

	/**
	 * @param dices the dices to set
	 */
	public void setDices(DiceCollection dices) {
		this.dices = dices;
	}

	/**
	 * @return the firstPlayer
	 */
	public PlayerCollection getFirstPlayer() {
		return firstPlayer;
	}

	/**
	 * @param firstPlayer the firstPlayer to set
	 */
	public void setFirstPlayer(PlayerCollection firstPlayer) {
		this.firstPlayer = firstPlayer;
	}

	/**
	 * @return the actualTurn
	 */
	public int getActualTurn() {
		return actualTurn;
	}

	/**
	 * @param actualTurn the actualTurn to set
	 */
	public void setActualTurn(int actualTurn) {
		this.actualTurn = actualTurn;
	}
}
